<!--{include admin/top.html}-->
	<div class="mainPage">
	<!--{if $act == 'index'}-->
	<script>
		function chkAll(obj){
			$("#frm input[type='checkbox'][name='id[]']").attr("checked",obj.checked);
		}
		function delAll(){
			if($(":input[type='checkbox'][name='id[]']:checked").length > 0){
				$("#frm").attr("action","{:parse_uri('admin_case-del')}");
				$("#frm").submit();
			}else{
				alert("请选择要删除的产品!");
				return false;
			}
		}
		function passAll(num){
			if($("input:[type='checkbox'][name='id[]']:checked").length > 0){
				num = parseInt(num)?parseInt(num):0;
				if(parseInt(num) < 1){
					$("#frm").attr("action","{:parse_uri('admin_case-pass')}");
				}else{
					$("#frm").attr("action","{:parse_uri('admin_case-recommend')}");
				}
				$("#frm").submit();
			}else{
				alert("请选择产品!");
				return false;
			}
		}
	</script>
		<h1 class="title">业务产品
			<span class='sub_menu'>
				&nbsp;<a href="{:parse_uri('admin_case-add')}">添加产品</a>
			</span>
		</h1>
		<form id="frm" style="margin:0;padding:0;" method="post" action="" >
		<table width="100%" align=center cellspacing=0 cellpadding=0 border=0>
		<tr >
			<td width="10%" align=center>
				<p><b>选择</b></p></td>
			<td width="30%" align=center><p><b>名称</b></p></td>
			<td width="12%" align=center><p><b>类别</b></p></td>
			<td width="10%" align=center><p><b>审核</b></p></td>
			<td width="8%" align=center><p><b>浏览</b></p></td>
			<td width="15%" align=center><p><b>日期</b></p></td>
			<td width="15%" align=center><p><b>操作</b></p></td>
		</tr>
		<!--{foreach $pros $k $v}-->
		<tr class="ctr">
			<td align=center><input type="checkbox" name="id[]" value="{$v['Id']}" /></td>
			<td align=center>
				<p>
					{if $v['pro_status'] == 2}<span style="color:#d00">[荐]</span>{/if} 
					{if $v['pro_pic']}<span style="color:green">[图]</span>{/if}
					{if $v['vod_id']}<span style="color:red">[视]</span>{/if}
					{$v['pro_name']|14}
				</p></td>
			<td align=center><p>{$v['cat_name']}</p></td>
			<td align=center><p>{if $v['pro_status']>=1}<span style="color:green">通过</span>{else}<span style="color:gray">未审核</span>{/if}</p></td>
			<td align=center><p>{$v['pro_views']}</p></td>
			<td align=center><p>{:date("Y-m-d",$v['pro_dateline'])}</p></td>
			<td align=center><p>
			<a href="{:parse_uri('admin_case-modify-id-%d',$v['Id'])}">修改</a> &nbsp;|&nbsp; 
			<a href="{:parse_uri('admin_case-del-id-%d',$v['Id'])}">删除</a></p></td>
		</tr>
		<!--{/foreach}-->
		<tr>
			<td   colspan=7 style="padding-top:4px;padding-bottom:0px;">
			<!--{include admin/page.html}-->
			<a href="javascript:void(0)" onclick="delAll()">删除所选</a>&nbsp;&nbsp;
			<a href="javascript:void(0)" onclick="passAll()">通过所选</a>&nbsp;&nbsp;
			<a href="javascript:void(0)" onclick="passAll(1)">推荐所选</a>
			</td>
		</tr>
		</table>
		</form>
	<!--{else if $act == 'add' || $act == 'modify'}-->
<script>
	var curTabIndex = 0;
	function showUpload(obj){
		if(obj.value=='true'){
			//true//
			if(obj.checked){
				$("#upload").hide();
				$("input[type=checkbox][value=false]").removeAttr('checked');
			}
		}else{
			if(obj.checked){
				$("#upload").show();
				$("input[type=checkbox][value=true]").removeAttr('checked');
			}else{
				$("#upload").hide();
			}
		}
	}
	function nextTab(){
		var nextId = 0;
		if(curTabIndex <3){
			nextId = curTabIndex + 1;
		}
		$("#tabNav"+nextId).trigger("onclick");
	}

	function getVods(){
		var str = Dialog('添加视频','{:parse_uri('admin_vod-add')}',0,0);
		if(str != undefined){
			eval("var d = "+str+" ;");
			if(d.result == true){
				$("#vod_id").append("<option value='"+d.id+"' selected>"+d.title+"</option>" );
			}
		}
	}

	function getTags(){
		var str = Dialog('选择标签','{:parse_uri('admin_other-tags-do-check')}',0,0);
		if(str == undefined){
			return false;
		}else if(str.length==0){
			return false;
		}
		str = str.split(",");
		var tags = $("#tags").val();
		for(var j=0;j<str.length;j++){
			var loc = parseInt(tags.InStr(str[j]));
			if(loc > -1){
				var reg  = "/,?"+str[j]+"/ig";
				tags = tags.replace(eval(reg),"");
				if(tags.substring(0,1)==","){
					tags = tags.substring(1,tags.length);
				}
			}else{
				if(tags.length == 0){
					tags = str[j];
				}else{
					tags += ","+str[j];
				}
			}
		}
		$("#tags").val(tags);
	}
	function show(obj,id){
		if($(obj).css("color") == "#f30"){
			return false;
		}else {
			$(".sub_menu a").css("color","").css("border","1px dashed none").css("background","none");
			$(obj).css("color","#f30").css("border","1px dashed #fff").css("background","black").blur();
			if($("#tab"+id).css("display") == "none"){
				$("#tab"+curTabIndex).css("display","none");
				$("#tab"+id).css("display","block");
			}
			curTabIndex = id;
		}
	}
	function tpl(obj){
		var v = $(obj).val();
		if(v == "0"){
			$("#attrDIV").html('');
			return false;
		}
		var tmp = v.split("-");
		var html = "";
		for(var i =0;i<tmp.length;i++){
			html +="<tr><td style='width:80px'><input name='attrName[]' value='"+tmp[i]+"' type='hidden' />"+tmp[i]+" : ";
			html +="<td align='left'><input name='attrVal[]' /></td></tr>";
		}
		$("#attrDIV").html(html);
	}
	function addNewUpload(){
		var html = "<div class='uploadEleDiv'><p>图片: <input name='userfile[]' onchange='reviewImg(this.value,this)' type='file'/> <a href='javascript:void(0)' onclick='setCoverImage(this)'>封面</a><div class='previewImage' style='background:url() no-repeat'></div></p>";
		html += "<p>描述: <textarea type='text' class='desc' name='uploadText[]'></textarea> <a href='javascript:void(0)' onclick='hideUpload(this)' style='color:red'>删除</a></p><input type='hidden'/></div>";
		$("#picDIV").append(html);
	}
	function hideUpload(obj){
		if(confirm('确定删除?')){
			var obj = $(obj).parent().parent();
			obj.fadeOut('500',function(){
				obj.remove();
			});
		}
	}
	function setCoverImage(obj){
		var currPic = "{$pro['pro_pic']}";
		if($(obj).parent().parent().hasClass("isCoverImage")){
			$(obj).parent().parent().removeClass('isCoverImage');
			$("#coverImage").val("none");
			$("#pro_pic").val(currPic);// 重置封面图片地址 ///
		}else{
			//alert($(".uploadEleDiv").index($(obj).parent().parent()));
			$("#coverImage").val($(".uploadEleDiv").index($(obj).parent().parent()));
			$(".uploadEleDiv").removeClass('isCoverImage');
			$(obj).parent().parent().addClass('isCoverImage');
			$("#pro_pic").val('');
		}
	}
	function reviewImg(src,obj){
		if( !src.match( /.jpg|.gif|.png|.bmp/i ) ){
			alert('图片格式无效！');
			return false;
		}
		if(src!=""){
			var imgObj = $(obj).parent().parent().find("div");
			$(obj).parent().parent().find("input[name='albumId[]']").attr("name","null");
			$("#previewObjID").attr("id","");
			imgObj.attr("id","previewObjID");
			Preview("previewObjID",src);
		}
	}
	 function Preview(obj,val) { 
	  	document.getElementById(obj).filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src =val;
	 }
	 function chkPrice(obj){
	 	if(!obj.value.match(/^\d+(\.\d{1,2})?$/i )){
	 		alert("请输入正确的产品价格!");
	 		obj.focus();
	 		obj.value="0.00";
	 	}	 	
	 }
	 function chkLink(obj){
	 	if(!obj.value.match(/^http:\/\/.*?$/i )){
	 		alert("请输入正确的商品地址,须带有http://");
	 		obj.focus();
	 		obj.value="";
			return false;
	 	}
		return true;
	 } 
</script>
		<h1 class="title">{if $act == 'add'}添加{else}修改{/if}产品
			<span class='sub_menu'>
				&nbsp;<a href="javascript:void(0)" onclick="show(this,0)" id="tabNav0" class="bglink" style="color:#f30">基本信息</a>
				&nbsp;<a href="javascript:void(0)" onclick="show(this,1)" id="tabNav1" class="nobglink">产品图册</a>
				&nbsp;<a href="javascript:void(0)" onclick="show(this,2)" id="tabNav2" class="nobglink">产品属性</a>
				&nbsp;<a href="javascript:void(0)" onclick="show(this,3)" id="tabNav3" class="nobglink">内容介绍</a>
				&nbsp;<a href="{:parse_uri('admin_case-index')}" class="nobglink">返回列表</a>
			</span>
		</h1>
		<form action="{:parse_uri('admin_case-save')}" id="frm" method="post" enctype="multipart/form-data">
		<div id="tab0">
		<p class="field-p"  style="line-height:30px;">
			<span style="word-spacing:18px;">名 称</span>: 
			<input name="pro_name" value="{$pro['pro_name']}" class="ipt" style="width:396px;" />
			<input name="pro_id" value="{$pro['Id']}" type="hidden"/>
		</p>
		<p class="field-p" style="line-height:30px;">
			<span style="word-spacing:18px;">类 别</span>: 
			<select style="width:100px;" name="cat_id">
			<!--{foreach $cats $k $v}-->
				<option value="{$v['Id']}" {if $v['Id'] == $pro['cat_id']}selected{/if}>{$v['cat_name']}</option>
				<!--{foreach $v['sub'] $subk $subv}-->
					<option value="{$subv['Id']}" {if $subv['Id'] == $pro['cat_id']}selected{/if}>&nbsp;&nbsp;{if $subk === 0 && sizeof($v['sub'])!=1}┌{else if $subk == (sizeof($v['sub'])-1)}└{else}├{/if}&nbsp;{$subv['cat_name']}</option>
				<!--{/foreach}-->
			<!--{/foreach}-->
			</select>
		</p>
		<p class="field-p"  style="line-height:30px;">
			<span style="word-spacing:18px;">价 格</span>: <input name="pro_price" id="pro_price" value="{$pro['pro_price']?$pro['pro_price']:'0.00'}" maxlength="30" class="ipt" onblur="chkPrice(this)" style="width:100px;" /> 
			<span class="errmsg">仅支持数字,精确到小数点后2位</span>
		</p>
		<p class="field-p"  style="line-height:30px;">
			<span style="word-spacing:18px;">产品链接</span>: 
			<input name="pro_link" id="pro_link" value="{$pro['pro_link']?$pro['pro_link']:''}" maxlength="30" class="ipt" style="width:300px;"  /> 
			<span class="errmsg">输入产品在其他网站的链接,例如: 淘宝,拍拍,百度有啊等</span>
		</p>
		<p class="field-p"  style="line-height:30px;">
			<span style="word-spacing:0.6px;">关 键 字</span>: 
			<input name="keywords" value="{$pro['pro_keywords']?$pro['pro_keywords']:'关键字'}" maxlength="30" class="ipt" style="width:300px;" /> 
			<span class="errmsg">英文逗号分隔,30字以内</span>
		</p>
		<p class="field-p"  style="line-height:30px;">
			<span style="word-spacing:18px;">标 签</span>: <input name="tags" id="tags" value="{$pro['pro_tags']?$pro['pro_tags']:''}" maxlength="30" class="ipt" style="width:300px;" /> 
			<a href="javascript:void(0)" onclick="getTags()"><span class="errmsg" style="word-spacing:2px;color:red">[&nbsp;标签列表&nbsp;]</span></a>
			<span class="errmsg">英文逗号分隔</span>
		</p>
		<p class="field-p"  style="line-height:30px;">
		<span style="word-spacing:18px;">外部视频</span>: 

			<select name="vod_id" id="vod_id">
				<option value="0">请选择视频</option>
				{foreach $vods $k $v}
				<option value="{$v['Id']}" {if $v['Id'] == $pro['vod_id']}selected{/if}>{$v['v_title']}</option>
				{/foreach}
			</select>
			<a href="javascript:void(0)" onclick="getVods()"><span class="errmsg" style="word-spacing:2px;color:red">[&nbsp;新增视频&nbsp;]</span></a>
		</p>
	

		</div>

		<div id="tab1" class="ProTab" style="display:none">
			<p class="field-p"  style="line-height:20px;">
				<a href="javascript:void(0)" onclick="addNewUpload()">添加图片</a>
				<input type="hidden" id="coverImage" name="coverImage" value=""/>
				<input type="hidden" id="pro_pic" name="pro_pic" value="{$pro['pro_pic']}"/>
			</p>
			<div id="picDIV" style="padding-left:20px;">
			{foreach $pro['album'] $k $v}
				<div class='uploadEleDiv{if $v['cover']==1} isCoverImage{/if}'>
					<p>
						图片: <input name='userfile[]' onchange="reviewImg(this.value,this)" type='file'/> 
						<a href='javascript:void(0)' onclick='setCoverImage(this)'>封面</a>
						<div class="previewImage" style="background:url({__UPLOAD__}/{:timg($v['pic'])}) no-repeat"></div>
					</p>
					<p>
						描述: <textarea type='text' class='desc' name='uploadText[]'>{$v['alb_des']}</textarea> 
							<a href='javascript:void(0)' onclick='hideUpload(this)' style='color:red'>删除</a>
					</p>
					<input type="hidden" name="albumId[]" value="{$v['Id']}" />
				</div>
				{if $v['cover']==1}<script>$("#coverImage").val('{$k}');</script>{/if}
			{/foreach}	
			</div>
			<p style="line-height:30px;"></p>
			
		</div>
		<div id="tab2" class="ProTab" style="display:none">
			<p><span style="word-spacing:3px;">模板 : &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
			<select onchange="tpl(this.options[this.options.selectedIndex])">
				<option value="0">请选择</option>
				{foreach $ptpl $k $v}
				{if md5(serialize($v['tpl'])) == md5(serialize($pro['attr']['key'])) }
				<option value="{foreach $v['tpl'] $tk $tv}{if $tk > 0}-{/if}{$tv}{/foreach}" selected >{$v['cname']}</option>
				{else}
				<option value="{foreach $v['tpl'] $tk $tv}{if $tk > 0}-{/if}{$tv}{/foreach}" >{$v['cname']}</option>
				{/if}
				{/foreach}
			</select>
			&nbsp;<a href="javascript:void(0)" onclick="location.href=location.href" style="color:Red;font-size:13px;">重置</a>
			</p>
			<table id="attrDIV" style="width:400px;margin-left:24px;margin-top:8px;">
			{foreach $pro['attr']['key'] $k $v}
				<tr>
					<td style='width:80px'>
						<input name='attrName[]' value="{$v}" type='hidden' /> {$v}: 
					<td align='left'>
						<input name='attrVal[]' value="{$pro['attr']['val'][$k]}" />
					</td>
				</tr>
			{/foreach}
			</table>

		</div>

		<div id="tab3" class="ProTab" style="display:none">
		<p >
		<textarea name="content" style="display:none">{$pro['content']}</textarea>
		</p>
		<p><iframe ID="Editor" name="Editor" src="{__HOST__}/public/Editor/index.html?ID=content" frameBorder="0" marginHeight="0" marginWidth="0" scrolling="No" style="height:320px;width:600px"></iframe></p>
		</div>
		<p style='margin-top:10px;'>
		<input type="button" onclick="nextTab()" value='下页'class="submit" />
		<input type="submit" value='提交'class="submit"/>
		审核通过: <input type="checkbox" name="pro_status" value="1" {if $pro['pro_status'] > 0}checked="checked"{/if}/>
		</p>
		<input type="hidden" name="id" value="{$art['Id']}"  />
		</form>
	<!--{/if}-->
	<div align="center" class="runtime"> {__TIMENOW__} Processed in {__RUNTIME__} second(s) {__QUERY__} queries &nbsp;</div>
</div>
</body>
</html>